package main

import "log"

func main() {
	var list = []int{1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 8}
	list = removeDuplicates(list)
	for i := 0; i < len(list); i++ {
		log.Println("v=", list[i])
	}
}

// 1,2,2,3,4  -> 1,2,3,4
// 移除数组中的重复项
func removeDuplicates(nums []int) []int {
	if len(nums) == 0 {
		return nums
	}
	var i = 0 // i是慢指针 j是快指针
	for j := 1; j < len(nums); j++ {
		if nums[j] != nums[i] {
			i++
			nums[i] = nums[j]
		}
	}
	return nums
}
